<?php

namespace App\Http\Validate\OpenShop\InvestmentPromotion;

use App\Http\Validate\BaseValidate;
use App\Models\OpenShop\InvestmentPromotion\OpenShopMainProcessModel;
use App\Service\OpenShop\Feishu\ConfigService;
use Illuminate\Validation\ValidationException;


/**
 * [ open_shop_user_work_experience 招商加盟 - 工作经验 ] - 校验规则
 *
 * @UserExperienceValidate
 * @package App\Http\Controllers
 * @date 2022/02/28 06:51:44
 * @author GreenLeaf <786407418@qq.com>
 */
class UserExperienceValidate extends BaseValidate
{

    public static function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    /**
     * 预处理参数
     *
     * @param array $data
     * @return array
     */
    public static function beforeValidate(array $data): array
    {
        $data = collect($data)->filter(function ($v) {
            if ($v === "") {
                return false;
            }
            return true;
        })->toArray();
        return parent::beforeValidate($data); // TODO: Change the autogenerated stub
    }

    /**
     * 获取规则信息
     *
     * @param array $fields
     * @return string[]
     */
    public static function getRules(array $fields = []): array
    {
        return self::getActuallyRules([
            'orderNo'              => 'bail|required|exists:' . OpenShopMainProcessModel::class . ',OrderNo',//
            'cateringExperience'   => 'sometimes|required|in:' . enumTransToRules(collect(ConfigService::config("openShop")["cateringExperience"])
                    ->pluck("name", "id")->toArray()),//是否有餐饮经验
            'joinChainExperience'  => 'sometimes|required|in:' . enumTransToRules(collect(ConfigService::config("openShop")["hasExperience"])
                    ->pluck("name", "id")->toArray()),//是否有加盟连锁经验
            'employmentExperience' => 'sometimes|required|in:' . enumTransToRules(collect(ConfigService::config("openShop")["hasExperience"])
                    ->pluck("name", "id")->toArray()),//是否有自营经验
            'workLife'             => 'sometimes|required|in:' . enumTransToRules(collect(ConfigService::config("openShop")["cateringExperience"])
                    ->pluck("name", "id")->toArray()),//工作年限
        ],
            $fields);
    }

    public static array $attributes = [
        'orderNo'              => '订单号',
        'cateringExperience'   => '是否有餐饮经验',
        'joinChainExperience'  => '是否有加盟连锁经验',
        'employmentExperience' => '是否有自营经验',
        'workLife'             => '工作年限',
    ];

    /**
     * 创建校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function insertValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            collect(self::getRules())->except(['orderNo'])->keys()->toArray()
        );
    }

    /**
     * 更新校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function updateValidate(array $requestParams): array
    {
        return self::baseValidate($requestParams, array_keys(self::getRules()));
    }

    /**
     * 删除校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function delValidate(array $requestParams): array
    {
        return self::getRequestParams($requestParams, array_keys(self::getRules()));
    }

    /**
     * 状态校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function statusValidate(array $requestParams): array
    {
        return self::getRequestParams($requestParams, array_keys(self::getRules()));
    }


}
